package com.hz.ys_production.dao;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.hz.framework.MyInterFace.SystemInterFace;
import com.hz.framework.dao.CommonDBDao;
import com.hz.framework.dao.CommonDao;
import com.hz.framework.util.CommonFunc;
import com.hz.framework.util.DateUtil;
import com.hz.framework.util.SqlParameter;
import com.hz.ys_production.bean.PresDailypaper;
import com.hz.ys_production.dbsql.DailyPaperSql;

/**
 * *****************************************************************************
 *               Copyright(c) 2010 by 哈尔滨华泽数码科技有限公司.
 *                       All rights reserved.
 *******************************************************************************
 *     File Name         :  com.hz.ys_stock.dao.MakingsDao.java
 *     Description(说明)	:  原材料管理
 * -----------------------------------------------------------------------------
 *     No.        Date              Revised by           Description	  
 *     1		Jun 8, 2011				韩飞	              Created
 *****************************************************************************
 */
public class DailyPaperDao implements SystemInterFace{
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能:查询原材料信息
	 */
	public String SelDailypaper(HttpServletRequest request){
		
		
		return DailyPaperSql.SEL_DAILYPAPER;
	}
	/**
	 * @author 韩飞
	 * @time Nov 17, 2011	
	 * @param puser
	 * @return
	 * @throws Exception 
	 * 方法功能: 保存原材料
	 */
	public boolean DoSaveDailyPaper( PresDailypaper mak ) throws Exception {
		boolean ins = false;
		CommonDao dbd= new CommonDao();
		if(mak!=null){
			mak.setEndtime(DateUtil.getDateTime());
			//保存或更新 
			ins = dbd.insertinfor(mak);
			if(ins){
				ins = dbd.executeSQL(DailyPaperSql.UPD_MACHINETASK_INFO, new SqlParameter("已完工",mak.getEndtime(),mak.getTaskid()));
				ins = dbd.executeSQL(DailyPaperSql.UPD_TASK_INFO, new SqlParameter("已完工",mak.getTaskid()));
				ins = dbd.executeSQL(DailyPaperSql.UPD_MACHINE_INFO, new SqlParameter("空闲",mak.getTaskid()));
				Map map = (Map)dbd.queryObjectByPS(DailyPaperSql.SEL_TASK_COM, new SqlParameter(mak.getTaskid()),null);
				if(map.get("ywg").equals(map.get("sy"))){
					ins = dbd.executeSQL(DailyPaperSql.UPD_ORDER_INFO, new SqlParameter("已完工",map.get("orderid")));
				}
			}
		}
		return ins;
	}
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能: 修改原材料信息
	 */
	public boolean UpdDailypaper(PresDailypaper mak){
		CommonDao dbo= new CommonDao();
		return dbo.updateinfor(mak);
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @param request
	 * @return 
	 * 方法功能: 删除 生产日报
	 */
	public boolean Del_DailyPaper(HttpServletRequest request){
		String taskid = CommonDao.isnull(request.getParameter("taskid"));
		CommonDBDao dbo= new CommonDBDao();
		return dbo.executeSQL(DailyPaperSql.DEL_DAILYPAPER_INFO, new SqlParameter(taskid));
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @param request
	 * @return 
	 * 方法功能: 根据 gid 查询 对应原材料信息
	 */
	public Map SelDailypaper_info(HttpServletRequest request) throws Exception {
		String did  = CommonDao.isnull(request.getParameter("did"));
		CommonDao dbd= new CommonDao();
		return (Map)dbd.queryObjectByPS(DailyPaperSql.SEL_DAILYPAPER_INFO, new SqlParameter(did),null);
	}
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能:查询原材料信息
	 */
	public List SelDailypaper(){
		CommonDBDao dbo= new CommonDBDao();
		return dbo.DBjsonList(DailyPaperSql.SEL_DAILYPAPER);
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能:查询生产单
	 */
	public Map SelTaskInfo(String taskid){
		CommonDBDao dbo= new CommonDBDao();
		return (Map)dbo.queryObjectByPS(DailyPaperSql.SEL_TASKINFO_INFO, new SqlParameter(taskid),null);
	}
}
